package com.project.workjob.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.workjob.entity.GjxlYb;
import com.project.workjob.mapper.GjxlYbMapper;
import com.project.workjob.service.GjxlYbService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GjxlYbServiceImpl implements GjxlYbService {

    @Resource
    private GjxlYbMapper gjxlYbMapper;

    @Override
    @DS("master")
    public List<GjxlYb> getListByDate(String datetime) {
        Example example = new Example(GjxlYb.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("report_time", datetime);
        List<GjxlYb> list = gjxlYbMapper.selectByExample(example);
        return list;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insert(List<GjxlYb> list) {
        for (GjxlYb entity : list) {
            gjxlYbMapper.insertSelective(entity);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void deleteByDate(String datetime) {
        Example example = new Example(GjxlYb.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("report_time", datetime);
        gjxlYbMapper.deleteByExample(example);
    }
}
